package com.cloud.rocketmq;

import com.cloud.message.MessageExtConst;
import org.springframework.stereotype.Component;

import java.lang.annotation.*;

/**
 * RocketMQ 消费者自动装配注解
 *
 * @author yzj
 */
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface MQConsumer {

    /**
     * 不同主题下消费者组名称不能重复
     */
    String consumerGroup();

    String topic();

    /**
     * 广播模式消费： BROADCASTING
     * 集群模式消费： CLUSTERING
     *
     * @return 消息模式
     */
    String messageMode() default MessageExtConst.MESSAGE_MODE_CLUSTERING;

    /**
     * 使用线程池并发消费: CONCURRENTLY("CONCURRENTLY"),
     * 单线程消费: ORDERLY("ORDERLY");
     *
     * @return 消费模式
     */
    String consumeMode() default MessageExtConst.CONSUME_MODE_CONCURRENTLY;

    /**
     * 主题标签
     */
    String[] tag() default {"*"};

}

/**
 * <p>
 * 消费者使用方法
 *
 * @MQConsumer(consumerGroup = "consumerTest", topic = "Test", tag = "Hello")
 * public class DemoConsumer extends AbstractMQPushConsumer<String> {}
 * </p>
 * 生成者使用方法
 * @Autowired MQProducer producer;
 * producer.sendMessageInTransaction("Test","Hello","Hello World",System.currentTimeMillis() + "");
 * </p>
 * 事务消息发送
 * @MQTransactionProducer(producerGroup = "demo",topic = "Test",tag = "Hello")
 * public class DemoListener extends AbstractMQTransactionProducer {}
 * </p>
 */